package com.car.common.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.car.common.Constant;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import cn.hutool.extra.qrcode.QrCodeUtil;

@Controller
@RequestMapping("/common")
public class CheckCodeController {
	
	/**
	 * @Title: checkCode
	 * @author: TiTanLee   
	 * @date: 2019年11月30日 下午2:22:25 
	 * @Description: 验证码
	 * @param session
	 * @param resp
	 * @throws IOException
	 * @return: void
	 */
	@RequestMapping("checkCode.do")
	public void checkCode(HttpSession session, HttpServletResponse resp) throws IOException {
		CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 10);
		String code = captcha.getCode();
		// 将验证码放入Session
		session.setAttribute(Constant.CHECK_CODE, code);
		// 将验证码对外输出
		captcha.write(resp.getOutputStream());
	}
	
	/**
	 * @Title: qrCode
	 * @author: TiTanLee   
	 * @date: 2019年11月30日 下午2:23:59 
	 * @Description: 二维码
	 * @param session
	 * @param resp
	 * @return: void
	 * @throws IOException 
	 */
	@RequestMapping("qrCode.do")
	public void qrCode(HttpSession session, HttpServletResponse resp) throws IOException {
		BufferedImage generate = QrCodeUtil.generate("https://www.cnblogs.com/lyang-a/", 200, 200);
		// 将img输出
		ImageIO.write(generate, "jpg", resp.getOutputStream());
	}

}
